package safari.model.buy;

import java.sql.SQLException;
import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;

public class BuyBoardDaoImpl implements BuyBoardDao {
	private SqlSessionTemplate sqlSessionTemplate;

	public BuyBoardDaoImpl(SqlSessionTemplate sqlSessionTemplate) {
		this.sqlSessionTemplate = sqlSessionTemplate;
	}
	
	/* 게시물 쓰기 */
	@Override
	public int insertContent(BuyBoardVO bvo) throws SQLException{
		return sqlSessionTemplate.insert("buy.insertContent", bvo);
	}
	
	/* 게시물 보기 */
	@Override
	public BuyBoardVO showContent(int no) throws SQLException{
		return sqlSessionTemplate.selectOne("buy.showContent", no);
	}
	
	/* 댓글 쓰기 */
	@Override
	public int insertComment(BuyCommentVO bcvo) throws SQLException{
		/*int result = sqlSessionTemplate.insert("buy.insertComment", bcvo);*/
		/*System.out.println("다오 댓글쓰기 결과:"+result);*/
		System.out.println("다오 댓글쓰기 bcvo:"+bcvo);
		return sqlSessionTemplate.insert("buy.insertComment", bcvo);
	}
	
	/*댓글 한 개 보기*/
	@Override
	public BuyCommentVO getComment(int bno) throws SQLException{
		System.out.println("다오 댓글보기"+bno+" 결과:"+sqlSessionTemplate.selectOne("buy.getComment",bno));
		return sqlSessionTemplate.selectOne("buy.getComment",bno);
	}
	
	/* 댓글 보기(list) */
	@Override
	public List<BuyCommentVO> getCommentList(int bno) throws SQLException{
		System.out.println("다오 댓글리스트 보기:"+bno+" 결과:"+sqlSessionTemplate.selectList("buy.getCommentList", bno));
		return sqlSessionTemplate.selectList("buy.getCommentList", bno);
	}
	
	/* 댓글 수정 */
	@Override
	public void updateComment(BuyCommentVO bcvo) throws SQLException{
		sqlSessionTemplate.update("buy.updateComment",bcvo);
	}
	
	/* 댓글 삭제 */
	@Override
	public int deleteComment(int no) throws SQLException{
		return sqlSessionTemplate.delete("buy.deleteComment",no);
	}
	/* 조회수 업데이트 */
	@Override
	public int updateHits(int no) throws SQLException{
		return sqlSessionTemplate.update("buy.updateHits",no);
	}
		
	@Override
	 /* 게시물 목록 */ 
	public List<BuyBoardVO> getContentList(int page) throws SQLException{
		return sqlSessionTemplate.selectList("buy.getContentList", page);
	}
	 
	/* 총 컨텐츠(게시물 수 확인) */
	@Override
	public int totalContents() throws SQLException{
		return sqlSessionTemplate.selectOne("buy.totalContents");
	}
	/* 총 댓글 */
	@Override
	public int totalComments() throws SQLException{
		return sqlSessionTemplate.selectOne("buy.totalComments");
	}
	
	/* 게시물 수정 */ 
	@Override
	public void updateContent(BuyBoardVO bvo) throws SQLException{
		System.out.println("다오임플"+bvo);
		sqlSessionTemplate.update("buy.updateContent",bvo);
	}
	
	/* 게시물 삭제 */
	@Override
	public int deleteContent(int no) throws SQLException{
		return sqlSessionTemplate.delete("buy.deleteContent",no);
	}
	
	/* no */
	@Override
	public int showNo() throws SQLException {
		return sqlSessionTemplate.selectOne("buy.showNo");
	}
}
